// 用户接口管理
import request from "@/utils/request";
import type {
  UserEditResponse,
  UserPageResponse,
  UserPageRequest,
  UserResponse,
  UserType,
  UserAllocRoleRequest,
  UserLoginRequest,
  UserLoginReponse,
} from "./types";

const API = {
  USER_LOGIN: "/user/login",
  USER_PAGE: "user/page",
  USER_GET_BY_ID: "/user/getById",
  USER_CREATE_OR_EDIT: "/user/createOrEdit",
  USER_REMOVE: "/user/remove",
  USER_ALLOC_ROLE: "/user/allocRole",
  USER_BATCH_REMOVE: "/user/batchRemove",
  USET_INFO: "/user/info",
} as const;

export const userLogin = (data: UserLoginRequest) =>
  request.post<any, UserLoginReponse>(API.USER_LOGIN, data);

export const userPage = (data: UserPageRequest) =>
  request.post<any, UserPageResponse>(API.USER_PAGE, data);

export const userCreateOrEdit = (data: UserType) =>
  request.post<any, UserEditResponse>(API.USER_CREATE_OR_EDIT, data);

export const userGetById = (id: number) =>
  request.get<any, UserResponse>(API.USER_GET_BY_ID + `/${id}`);

export const userRemove = (id: number) =>
  request.delete<any, UserEditResponse>(API.USER_REMOVE + `/${id}`);

export const userAllocRole = (data: UserAllocRoleRequest) =>
  request.post<any, UserEditResponse>(API.USER_ALLOC_ROLE, data);

export const batchRemove = (idList: number[]) =>
  request.delete<any, UserEditResponse>(API.USER_BATCH_REMOVE, {
    data: idList,
  });

export const userInfo = () => request.get<any, UserResponse>(API.USET_INFO);
